package com.shxc.smarttrade.kvb.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.base.BaseFragment;
import com.shxc.smarttrade.kvb.activity.KvbOpenAccountActivity;

import org.xchris.view.annotation.ContentView;
import org.xchris.view.annotation.Event;
import org.xchris.view.annotation.ViewInject;

/**
 * KVB开户 三.签订协议
 */
@ContentView(R.layout.fragment_kvb_3)
public class KvbOpen3Fragment extends BaseFragment {

    @ViewInject(R.id.webview)
    WebView webview;
    @ViewInject(R.id.check_imageview)
    ImageView check_imageview;
    @ViewInject(R.id.next_button)
    Button next_button;

    boolean isAgree = false;
    String url = "http://testww.whjyds.com/wawaji/agreement.html";

    private KvbOpenAccountActivity kvbOpenAccountActivity;

    @Event({R.id.check_imageview, R.id.next_button})
    private void onClick(View view) {
        switch (view.getId()) {
            case R.id.check_imageview:
                //协议
                isAgree = !isAgree;
                checkIsAgree();
                break;
            case R.id.next_button:
                //下一步
//                kvbOpenAccountActivity.makeProgress(4);
                kvbOpenAccountActivity.openKvbAccount();
                break;
        }
    }



    private void checkIsAgree() {
        if (isAgree) {
            next_button.setEnabled(true);
            check_imageview.setImageResource(R.mipmap.choose_icon);
            next_button.setBackgroundResource(R.drawable.selector_bg_kvb);
        } else {
            next_button.setEnabled(false);
            check_imageview.setImageResource(R.mipmap.unchoose_icon);
            next_button.setBackgroundColor(resources.getColor(R.color.kvb_unclick));
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        kvbOpenAccountActivity = (KvbOpenAccountActivity) getActivity();
        WebSettings settings = webview.getSettings();
        settings.setSupportZoom(true);
        settings.setTextSize(WebSettings.TextSize.LARGEST);
        webview.loadUrl(url);
        checkIsAgree();
    }

}
